#include <stdio.h>
#include <sqlite3.h>
#include <string.h>

#define MAX_LINE_LENGTH 1024
#define MAX_WORD_LENGTH 100
#define MAX_DEFINITION_LENGTH 500

int main(int argc, char const *argv[])
{
    sqlite3 *db;
    char sql[256] = {0};  // 扩大缓冲区大小以适应插入语句

    // 打开数据库
    if (sqlite3_open("./User.db", &db) != SQLITE_OK)
    {
        fprintf(stderr, "%s\n", sqlite3_errmsg(db));
        return -1;
    }

    // 创建用户表
    char *errmsg = NULL;
    strcpy(sql, "create table if not exists user(name char primary key, password char);");
    if (sqlite3_exec(db, sql, NULL, NULL, &errmsg) != SQLITE_OK)
    {
        fprintf(stderr, "create user table error: %s\n", errmsg);
    }
    else
    {
        printf("user表创建成功\n");

        // 插入一条数据 (admin, admin)
        strcpy(sql, "insert into user (name, password) values ('admin', 'admin');");
        if (sqlite3_exec(db, sql, NULL, NULL, &errmsg) != SQLITE_OK)
        {
            fprintf(stderr, "insert data error: %s\n", errmsg);
        }
        else
        {
            printf("数据插入成功\n");
        }
    }

    // 关闭数据库
    sqlite3_close(db);

    return 0;
}
